/*************************************
 * Created by WebStorm
 * Author : 艾尼亚尔·毛拉吾提
 * QQ : 524155792  WeChat : ainiyar0124
 * Created Time :2024/2/5 18:39
 Desc :
 **************************************/

import {http} from '@/utils/http/index.ts';
import {isObject,isArray} from "@/utils/is.ts";


/**
 * post请求
 * @param url 请求地址
 * @param params  参数
 */
export function postRequest(url: string, params: any) {
    return http.request({
            url: url,
            method: 'POST',
            params,
        }
    );
}
export function uploadFileRequest(url: string, params: any) {
    return http.request({
            url: url,
            method: 'POST',
            params,
            headers: {'Content-Type': 'multipart/form-data'}
        }
    );
}

/**
 * get请求
 * @param url 请求地址
 * @param params 参数
 * @param rule 传参数模式  默认:false  false是:xxx/xxx?name=xxx  true是: xxx/xxx/{name}
 */
export function getRequest(url: string, params: any = null, rule: boolean = false) {
    let urls = url;
    if (rule) {
        for (const item in params) {
            urls += '/'+params[item];
        }
        return http.request({
                url: urls,
                method: 'GET',
            }
        );
    } else {
        return http.request({
                url: urls,
                method: 'GET',
                params,
            }
        );
    }
}

/**
 * post put请求
 * @param url 请求地址
 * @param params 参数
 * @param method  请求模式 默认：POST
 */
export function postPutRequest(url: string, params: any, method: string = 'POST') {
    return http.request({
            url: url,
            method: method,
            params,
        }
    );
}

/**
 * delete请求
 * @param url 请求地址
 * @param params 参数
 */
export function delRequest(url: string, params: any) {
    if (!isObject(params) && !isArray(params)) {
        return http.request({
                url:  url + '/' + params,
                method: 'DELETE'
            }
        );
    } else {
        return http.request({
                url:  url,
                method: 'DELETE',
                params,
            }
        );
    }
}






